/**
 * 自定义公共函数
 */
var myfn = {};
/**
 * 测试函数test1
 * vk.myfn.test1();
 */
myfn.test1 = function(obj = {}) {
	let vk = uni.vk;
	console.log("执行了自定义公共函数test1");
	return obj;
};

myfn.numberToChinese = function (num) {
	var chineseNumMap = [
		'零', '一', '二', '三', '四', '五', '六', '七', '八', '九'
	];
	var chineseUnitMap = {
		'0': '十', '1': '十', '2': '百', '3': '千', '4': '万',
		'5': '亿', '6': '十亿', '7': '百亿', '8': '千亿', '9': '万亿'
	};

	var strNum = String(num).replace(/(^0*)/g, ''); // 去除前导零
	var units = ['', '十', '百', '千'];
	var result = '';
	var unitPos = 0;

	for (var i = strNum.length - 1; i >= 0; i--) {
		var n = parseInt(strNum[i]);
		if (n !== 0) {
			result = chineseNumMap[n] + (unitPos % 4 === 0 ? chineseUnitMap[n] : units[unitPos % 4]) + result;
		}
		unitPos++;
	}

	if (result === '') {
		return '零';
	}

	return result;
}

export default myfn;
